#ifndef _IROBOT_CREATE_DRIVER_
#define _IROBOT_CREATE_DRIVER_

// Create OI Command Opcodes, should start with CMD_
#define CMD_START           128
#define CMD_BAUD            129
#define CMD_CONTROL         130
#define CMD_SAFE            131
#define CMD_FULL            132
#define CMD_SPOT            134
#define CMD_COVER           135
#define CMD_DEMO            136
#define CMD_DRIVE           137
#define CMD_LOW_SIDE        138
#define CMD_LEDS            139
#define CMD_SONG            140
#define CMD_PLAY            141
#define CMD_SENSORS         142
#define CMD_COVER_DOCK      143
#define CMD_PWM_LOW_SIDE    144
#define CMD_DRIVE_DIRECT    145
#define CMD_DIGITAL_OUT     147
#define CMD_STREAM          148
#define CMD_QUERY_LIST      149
#define CMD_PAUSE_RESUME    150
#define CMD_SEND_IR         151
#define CMD_SCRIPT          152
#define CMD_PLAY_SCRIPT     153
#define CMD_SHOW_SCRIPT     154
#define CMD_WAIT_TIME       155
#define CMD_WAIT_DISTANCE   156
#define CMD_WAIT_ANGLE      157
#define CMD_WAIT_EVENT      158

// Baud Codes - should start with BAUD_
#define BAUD_300            0
#define BAUD_600            1
#define BAUD_1200           2
#define BAUD_2400           3
#define BAUD_4800           4
#define BAUD_9600           5
#define BAUD_14400          6
#define BAUD_19200          7
#define BAUD_28800          8
#define BAUD_38400          9
#define BAUD_57600          10
#define BAUD_115200         11

// Demos
#define DEMO_ABORT          255
#define DEMO_COVERANDDUCK   1
#define DEMO_SPOTCOVER      2
#define DEMO_MOUSE          3
#define DEMO_FIGUREEIGHT    4
#define DEMO_WIMP           5
#define DEMO_HOME           6
#define DEMO_TAG            7
#define DEMO_PACHELBEL      8
#define DEMO_BANJO          9

// Modes
#define MODE_SAFE           0
#define MODE_FULL           1

// LEDs - combine with | to access both LEDs
#define LED_PLAY            2
#define LED_ADVANCE         8

// Digital outputs - should start with DOUT_
#define DOUT_OUTPUT1         1
#define DOUT_OUTPUT2         2
#define DOUT_OUTPUT3         4

// Low side drivers - should start with LOW_
#define LOW_OUTPUT1         1
#define LOW_OUTPUT2         2
#define LOW_OUTPUT3         4

// Group packet sizes (in bytes)
#define PCKT_GROUP0         26
#define PCKT_GROUP1         10
#define PCKT_GROUP2         6
#define PCKT_GROUP3         10
#define PCKT_GROUP4         14
#define PCKT_GROUP5         12
#define PCKT_GROUP6         52

// Buttons on create
#define BTN_PLAY            1
#define BTN_ADVANCE         4

// Cargo Bay Digital Inputs
#define DIN_INPUT0          1
#define DIN_INPUT1          2
#define DIN_INPUT2          4
#define DIN_INPUT3          8
#define DIN_BAUD_CHANGE     16

// Charging Sources Available
#define CHRG_INTERNAL       1
#define CHRG_HOME_BASE      2

// OI Modes
#define OI_OFF              0
#define OI_PASSIVE          1
#define OI_SAFE             2
#define OI_FULL             3

typedef struct
{
    u8  bumps_wheels;       // Packet ID: 7
    u8  wall;               // Packet ID: 8
    u8  cliff_left;         // Packet ID: 9
    u8  cliff_front_left;   // Packet ID: 10
    u8  cliff_front_right;  // Packet ID: 11
    u8  cliff_right;        // Packet ID: 12
    u8  cliff_vwall;        // Packet ID: 13
    u8  low_side;           // Packet ID: 14
    u16 unused;             // Packet ID: 15-16
    u8  infrared;           // Packet ID: 17
    u8  buttons;            // Packet ID: 18
    s16 distance;           // Packet ID: 19
    s16 angle;              // Packet ID: 20
    u8  state_charging;     // Packet ID: 21
    u16 voltage;            // Packet ID: 22
    s16 current;            // Packet ID: 23
    s8  battery_temp;       // Packet ID: 24
    u16 battery_charge;     // Packet ID: 25
    u16 battery_capacity;   // Packet ID: 26
} CREATE_DATA;
    

u8 Create_Start( USART_TypeDef* USARTx, u8 mode );
u8 Create_SetBaudRate( USART_TypeDef* USARTx, u8 baud_code);
u8 Create_SetMode( USART_TypeDef* USARTx, u8 mode );
u8 Create_RunDemo( USART_TypeDef* USARTx, u8 demo );
u8 Create_Drive( USART_TypeDef* USARTx, s16 velocity, s16 radius);
u8 Create_DriveDirect( USART_TypeDef* USARTx, s16 right_velocity, s16 left_velocity);
u8 Create_DriveMillimeters( USART_TypeDef* USARTx, s16 distance, s16 velocity);
u8 Create_TurnAngle( USART_TypeDef* USARTx, s16 angle, s16 velocity);
s16 Create_GetAngle( USART_TypeDef* USARTx);
s16 Create_GetDistance( USART_TypeDef* USARTx);
u8 Create_GetDistAngle( USART_TypeDef* USARTx, s16* dist, s16* angle);
u8 Create_GetBumpers( USART_TypeDef* USARTx );
u8 Create_GetData( USART_TypeDef* USARTx, CREATE_DATA* pCD );

int sendchar (int c);


#endif //_IROBOT_CREATE_DRIVER_